package com.nike.amoeba.bean.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.nike.amoeba.bean.db.TaskStockBean

/**
 * User: Nike
 *  2024/5/24 16:23
 */
@Dao
interface TaskStockDao {

    /**
     * 增
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun add(vararg bean: TaskStockBean)

    //删除数据库表全部数据
    @Query("delete from TaskStockBean")
    suspend fun deleteAll()

    //根据用户ID删除全部
    @Query("DELETE FROM TaskStockBean WHERE userId = :userId AND companyId = :companyId")
    suspend fun deleteById(userId: String, companyId: String)


    /**
     * 查
     */
    @Query("SELECT * FROM TaskStockBean")
    fun findAll(): List<TaskStockBean>

    /**
     * 改
     */
    @Update
    suspend fun update(bean: TaskStockBean)

    //根据用户ID查询全部
    @Query("SELECT * FROM TaskStockBean WHERE userId = :userId AND companyId = :companyId AND code = :code")
    fun findById(userId: String?, companyId: String?, code: String?): List<TaskStockBean>


}